<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('预约记录列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>客户名称：</label>
                            <input type="text" name="cname"/>
                        </li>
                        <li>
                            <label>证件号码：</label>
                            <input type="text" name="cardNum"/>
                        </li>
                        <li>
                            <label>联系电话：</label>
                            <input type="text" name="telNo"/>
                        </li>
                        <li>
                            <label>客户经理：</label>
                            <input type="text" name="userName"/>
                        </li>
                        <li>
                            <label>产品类型：</label>
                            <select name="prdType" th:with="type=${@dict.getType('prd_typ')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-date">
                            <label>预约时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="sts" th:with="type=${@dict.getType('sem_recommend_sts')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <!--<li>-->
                        <!--<label>归属机构：</label>-->
                        <!--<input type="text" name="deptName"/>-->
                        <!--</li>-->

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="statistics:reservRecord:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prdTypeDatas = [[${@dict.getType('prd_typ')}]];
    var stsDatas = [[${@dict.getType('sem_recommend_sts')}]];
    var prdDatas = [[${@ecardPrd.ecardPrdInfoList()}]];
    var prefix = ctx + "statistics/reservRecord";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "预约记录",
            columns: [{
                checkbox: true
            },
                {
                    field: 'cname',
                    title: '客户名称'
                },
                {
                    field: 'cardNum',
                    title: '证件号码'
                },
                {
                    field: 'linkman',
                    title: '联系人(企业)'
                },
                {
                    field: 'telNo',
                    title: '联系电话'
                },
                {
                    field: 'prdType',
                    title: '产品类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(prdTypeDatas, value);
                    }
                },
                {
                    field: 'resPrdId',
                    title: '预约产品',
                    formatter: function (value, row, index) {
                        return selectPrdName(prdDatas, value);
                    }
                },
                {
                    field: 'resTime',
                    title: '预约时间'
                },
                {
                    field: 'sts',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(stsDatas, value);
                    }
                },
                {
                    field: 'prdId',
                    title: '办理产品',
                    formatter: function (value, row, index) {
                        return selectPrdName(prdDatas, value);
                    }
                },
                {
                    field: 'numbers',
                    title: '办理数量',
                    align: 'right'
                },
                {
                    field: 'prdUnit',
                    title: '计量单位'
                },
                {
                    field: 'acceptTime',
                    title: '办理时间'
                },
                {
                    field: 'useTimes',
                    title: '耗时(小时)'
                },
                {
                    field: 'userName',
                    title: '客户经理'
                },
                {
                    field: 'deptName',
                    title: '归属机构'
                },
                {
                    field: 'refUserName',
                    title: '推介人'
                },
             /*   {
                    field: 'reportUrl',
                    title: '风险报告',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.reportUrl, 500, 900, 'blank');
                    }
                },*/
                {
                    field: 'pdfReport',
                    title: '报告文件',
                    formatter: function (value, row, index) {
                        return getPdfName(row.pdfReport);
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function selectPrdName(prdDatas, value) {
        if ($.common.isEmpty(prdDatas) || $.common.isEmpty(value)) {
            return '';
        }
        var actions = [];
        $.each(prdDatas, function (index, prd) {
            if (prd.prdId == ('' + value)) {
                var listClass = $.common.equals("default", prd.listClass) || $.common.isEmpty(prd.listClass) ? "" : "badge badge-" + prd.listClass;
                actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, prd.prdName));
                return false;
            }
        });
        return actions.join('');
    }

    function getPdfName(value) {

        if ($.common.isEmpty(value) || $.common.isEmpty(value)) {
            return '';
        }
        var str = "";
        var json = JSON.parse(value);
        //初审报告
        if (json.hasOwnProperty("reportUrl")) {
            console.log(json["reportUrl"]);
            str += "<li><a href='" + json["reportUrl"] + "' target=\"_blank\"  style=\"margin-top: 2px;\">初审报告</a></li>";
        }
        //财税分析报告
        if (json.hasOwnProperty("taxReportUrl")) {
            console.log(json["taxReportUrl"]);
            str += "<li><a href='" + json["taxReportUrl"] + "' target=\"_blank\"  style=\"margin-top: 2px;\">财税分析报告</a></li>";
        }
        //交易分析报告
        if (json.hasOwnProperty("transReportUrl")) {
            console.log(json["transReportUrl"]);
            str += "<li><a href='" + json["transReportUrl"] + "' target=\"_blank\"  style=\"margin-top: 2px;\">交易分析报告</a></li>";
        }
        return str;
    }
</script>
</body>
</html>